package cn.net.shuxing.yifu.common.service;

import cn.net.shuxing.yifu.common.bean.Role;
import cn.net.shuxing.yifu.common.bean.RoleGroup;
import cn.net.shuxing.yifu.common.mapper.RoleGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleGroupService extends BaseService<RoleGroup, RoleGroupMapper>{

    @Autowired
    private RoleService roleService;

    public RoleGroupService insertRoleGroup(String roleGroupName)
    {
        RoleGroup roleGroup = new RoleGroup();
        roleGroup.setName(roleGroupName);
        mapper.insertSelective(roleGroup);
        return this;
    }

    @Override
    protected void complete(RoleGroup roleGroup)
    {
        if (roleGroup == null)
            return;
        Integer id = roleGroup.getId();
        Role role  = new Role();
        role.clearCreateTimeAndUpdateTime();
        role.setRoleGroupId(id);

        List<Role> roles = roleService.gets(role);


        roleGroup.setRoleList(roles);
    }
}
